﻿using DBVisitor.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBVisitor.DBConditions
{
    public class MaxConditionElement<RowType> : IConditionElement where RowType : new()
    {
        public Column Column { get; protected set; }
        public Table Table { get; protected set; }
        public IWhere<RowType> Scope { get; protected set; }

        public MaxConditionElement(Column column, Table table, IWhere<RowType> scope = null)
        {
            Column = column;
            Table = table;
            Scope = scope;
        }
        public virtual string SerializeToText()
        {
            return $"{Column.Name}=(Select Max({Column.Name}) in {(Scope?.IsEmpty??true ? Table.Name : $"(Select * from {Table.Name} where {Scope.SerializeContent()})")})";
        }
    }
}
